import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:loxen/view/content_widget.dart';
import 'package:loxen/view/inspiration/inspiration_detail_widget.dart';
import 'package:loxen/view/inspiration/inspiration_style_widget.dart';
import 'package:loxen/view/login/binding_phone_page.dart';
import 'package:loxen/view/login/attestation_company.dart';
import 'package:loxen/view/login/attestation_finish.dart';
import 'package:loxen/view/login/forget_pwd.dart';
import 'package:loxen/view/login/forget_pwd_page.dart';
import 'package:loxen/view/login/prompt_page.dart';
import 'package:loxen/view/master/collection_file_widget.dart';
import 'package:loxen/view/master/file_info_widget.dart';
import 'package:loxen/view/master/file_list_widget.dart';
import 'package:loxen/view/material/material_category_widget.dart';
import 'package:loxen/view/material/material_detail_widget.dart';
import 'package:loxen/view/material/material_order_receive/material_order_receive_widget.dart';
import 'package:loxen/view/mine/mine_comments_widget.dart';
import 'package:loxen/view/mine/mine_followers_widget.dart';
import 'package:loxen/view/mine/mine_info_edit_widget.dart';
import 'package:loxen/view/mine/mine_like_widget.dart';
import 'package:loxen/view/mine/mine_msg_widget.dart';
import 'package:loxen/view/mine/mine_page_widget.dart';
import 'package:loxen/view/mine/mine_study_list_widget.dart';
import 'package:loxen/view/mine/mine_studys_file_widget.dart';
import 'package:loxen/view/mine/mine_user_info_widget.dart';
import 'package:loxen/view/mine/mine_works_widget.dart';
import 'package:loxen/view/mine/settings/about_us_widget.dart';
import 'package:loxen/view/mine/settings/agreement_widget.dart';
import 'package:loxen/view/mine/settings/feedback_widget.dart';
import 'package:loxen/view/mine/settings/mine_policy_text.dart';
import 'package:loxen/view/mine/settings/policy_wiget.dart';
import 'package:loxen/view/mine/settings/privacy_policy_widget.dart';
import 'package:loxen/view/mine/settings/mine_settings_widget.dart';
import 'package:loxen/view/mine/settings/modify_password_widget.dart';
import 'package:loxen/view/report_widget.dart';
import 'package:loxen/view/search/search_result_widget.dart';
import 'package:loxen/view/search/search_widget.dart';
import 'package:loxen/view/study/study_detail_widget.dart';

class Routes {
  static const String main_page = '/main/mainPage';
  static const String login_page = '/login';
  static const String login_code_page = '/login/code';

  static const String report_page = '/report';
  static const String report_content = '/report/content';
  static const String register = '/register';
  static const String forget = '/forget';
  static const String prompt = '/forget/prompt';
  static const String forgetpwd = '/forgetpwd';
  static const String binding_phone = '/binding/phone';
  static const String attestation_type_company = '/attestation/type/company';
  static const String attestation_finish = '/attestation/finish';

  static const String inspiration_detail = '/inspiration/detail';
  static const String inspiration_style = '/inspiration/style';

  static const String material_category = '/material/category';
  static const String material_detail = '/material/detail';
  static const String material_order = '/material/order';
  static const String material_order_receive = '/material/order/receive';

  static const String master_file_info = '/master/file/info';
  static const String master_file_list = '/master/file/list';
  static const String master_file_add = '/master/file/add';

  /// ***********  学习 *************************/
  static const String study_detail = '/study/detail';
  static const String search = '/search';
  static const String search_result = '/search/result';

  /// ***********  我的菜单*************************/
  static const String mine = '/mine';
  static const String mineMsg = '/mine/msg';
  static const String mineInfoEdit = '/mine/info';
  static const String mineStudys = '/mine/study';
  static const String mineStudyFolder = '/mine/study/folder';
  static const String mineWorks = '/mine/works';
  static const String mineAddressEdit = '/mine/address/edit';
  static const String mineFollower = '/mine/follower';
  static const String mineLike = '/mine/like';
  static const String mineComment = '/mine/comment';
  static const String mineSettings = '/mine/setting';
  static const String mine_user_info = 'mine/user/info';

  /// ***********  我的_设置 *************************/

  static const String privacyPolicy = '/settings/privacyPolicy';
  static const String modifyPassword = '/settings/modifyPassword';
  static const String feedback = '/settings/feedback';
  static const String aboutUs = '/settings/about';
  static const String agreement = '/settings/agreement';
  static const String policy = '/settings/policy';
  static const String mine_policy_text = '/settings/mine/policy/text';

  static Route configRoutes(RouteSettings settings) {
    String name = settings.name;
    Object data = settings.arguments;
    return MaterialPageRoute(builder: (context) => _findPage(name, data));
  }

  static _findPage(String name, Object data) {
    Widget page;
    switch (name) {
      case report_content:
        Map map = data as Map;
        page = ContentWidget(map['name'], map['type'], map['id'], map['reportType']);
        break;
      case report_page:
        Map map = data as Map;
        page = ReportWidget(map['id'], map['reportType']);
        break;
      case forget:
        page = FoundPwdPage();
        break;
      //收不到验证码提示信息
      case prompt:
        page = CanCode();
        break;
      case binding_phone:
        if (data is Map) {
          page = BindingPhonePage(openid: data['openid'], platform: data['platform']);
        }
        break;
      case forgetpwd:
        if (data is Map) {
          page = ChangePwdPage(
            mobile: data['mobile'],
            code: data['code'],
          );
        }
        break;
      //公司类型
      case attestation_type_company:
        page = CompanyType();
        break;
      //验证审核页面
      case attestation_finish:
        page = FinishAttestation();
        break;
      case inspiration_style:
        if (data is Map) {
          var bean = data['bean'];
          var style = data['style'];
          page = InspirationStyleWidget(
            styleBean: bean,
            style: style,
          );
        } else {
          page = InspirationStyleWidget();
        }
        break;
      case inspiration_detail:
        page = InspirationDetailWidget(
          detail: data,
        );
        break;
      case search:
        if (data is Map) {
          var mType = data['mType'];
          var studyCategory = data['studyCategory'];
          var hintText = data['hintText'];
          page = SearchWidget(
            mType: mType,
            studyCategory: studyCategory,
            hintText: hintText,
          );
        } else {
          page = SearchWidget();
        }
        break;
      case search_result:
        if (data is Map) {
          page = SearchResultWidget(
              mType: data['type'], data: data['data'], studyCategory: data['studyCategory']);
        } else {
          page = SearchResultWidget();
        }
        break;
      case material_category:
        page = MaterialCategoryWidget(
          category: data,
        );
        break;
      case material_detail:
        page = MaterialDetailWidget(
          id: data,
        );
        break;
      case material_order_receive:
        page = MaterialOrderReceiveWidget();
        break;
      case study_detail:
        print(data);
        if (data is Map) {
          page = StudyDetailWidget(
            detail: data['detail'],
            currentCategory: data['currentCategory'],
          );
        } else {
          page = StudyDetailWidget();
        }
        break;
      case master_file_info:
        if (data is Map) {
          page = FileInfoWidget(
            file: data['file'],
            type: data['type'],
            isMe: data['isMe'],
            userId: data['userId'],
          );
        }
        break;
      case master_file_list:
        if (data is Map) {
          page = FileListWidget(
            type: data['type'],
            userId: data['userId'],
            isMe: data['isMe'],
          );
        } else {
          page = FileListWidget();
        }
        break;
      case master_file_add:
        if (data is Map) {
          page = CollectionFileWidget(fileType: data['type'], id: data['id']);
        } else {
          page = CollectionFileWidget();
        }
        break;
      case mine_user_info:
        page = MineUserInfoWidget(userId: data);
        return page;
      /******************我的菜单*****************/
      // 我的菜单
      case mine:
        page = MinePageWidget();
        break;
      // 我的通知消息
      case mineMsg:
        page = MineMsgWidget();
        break;
      // 我的信息修改
      case mineInfoEdit:
        page = MineInfoEditWidget(user: data);
        break;
      // 我的学习
      case mineStudys:
//        page = MineStudyWidget();
        page = MineStudyFileWidget();
        break;
      // 我的学习-tab
      case mineStudyFolder:
        if (data is List) {
          page = MineStudyListWidget(
            title: data[0],
            type: data[1],
            folder: data[2],
          );
        } else {
          page = MineStudyListWidget();
        }
        break;
      // 我的作品
      case mineWorks:
        page = MineWorksWidget();
        break;
      // 我关注的人
      case mineFollower:
        page = MineFollowerWidget();
        break;
      // 我赞过的
      case mineLike:
        page = MineLikeWidget();
        break;
      // 我的评论
      case mineComment:
        page = MineCommentWidget();
        break;
      // 我的设置
      case mineSettings:
        page = MineSettingsWidget();
        break;

      /******************我的_设置*****************/
      // 设置_隐私策略
      case privacyPolicy:
        page = PrivacyPolicyWidget();
        break;
      // 设置_修改密码
      case modifyPassword:
        page = ModifyPasswordWidget();
        break;
      // 设置_意见反馈
      case feedback:
        page = FeedbackWidget();
        break;
      // 设置_意见反馈
      case aboutUs:
        page = AboutUsWidget();
        break;
      // 设置_服务协议
      case agreement:
        page = AgreementWidget();
        break;
      case policy:
        page = PolicyWidget();
        break;
      // 设置_隐私政策文本
      case mine_policy_text:
        page = MinePolicyText();
        break;
    }
    return page;
  }
}
